﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for cls_tbNGUOIBANHANG_CHINHANH
/// </summary>
public class cls_tbNGUOIBANHANG_CHINHANH
{
	public cls_tbNGUOIBANHANG_CHINHANH()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public static DataTable GetAll()
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        try
        {
            dt = connect.GetSelectCommand("tbNGUOIBANHANG_CHINHANH_GetAll", null);
        }
        catch
        {
            dt = null;
        }
        return dt;
    }
    public static DataTable GetbyMaCN(string F_MACN)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MACN", F_MACN);
        try
        {
            dt = connect.GetSelectCommand("tbNGUOIBANHANG_CHINHANH_GetbyMaCN", para);
        }
        catch
        {
            dt = null;
        }
        return dt;
    }
    public static DataTable GetNguoibanhang_byMaCN(string F_MACN)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MACN", F_MACN);
        try
        {
            dt = connect.GetSelectCommand("tbNGUOIBANHANG_CHINHANH_GetNguoibanhang_byMaCN", para);
        }
        catch
        {
            dt = null;
        }
        return dt;
    }

    public static string Insert(string F_MACN, string NGUOIBANHANG, string GHICHU)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[3];
        
        para[0] = new SqlParameter("@F_MACN", F_MACN);
        para[1] = new SqlParameter("@NGUOIBANHANG", NGUOIBANHANG);
        para[2] = new SqlParameter("@GHICHU", GHICHU);

        try
        {
            connect.ExecuteQuery("tbNGUOIBANHANG_CHINHANH_Insert", para);
            return "OK";
        }
        catch
        { return "ERR"; }
    }

    public static string Update(int ID, string F_MACN, string NGUOIBANHANG, string GHICHU)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[4];
        para[0] = new SqlParameter("@ID", ID);
        para[1] = new SqlParameter("@F_MACN", F_MACN);
        para[2] = new SqlParameter("@NGUOIBANHANG", NGUOIBANHANG);
        para[3] = new SqlParameter("@GHICHU", GHICHU);
        
        try
        {
            connect.ExecuteQuery("tbNGUOIBANHANG_CHINHANH_Update", para);
            return "OK";
        }
        catch
        { return "ERR"; }
    }

    public static string Delete(int ID)
    {
        DatabaseConnect connect = new DatabaseConnect();

        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@ID", ID);

        try
        {
            connect.ExecuteQuery("tbNGUOIBANHANG_CHINHANH_Delete", para);
            return "OK";
        }
        catch { return "ERR"; }
    }
}